import { AxiosRequestConfig } from 'axios'
import { contextBridge, ipcRenderer } from 'electron'

contextBridge.exposeInMainWorld('API', {
  request: {
    http(config: AxiosRequestConfig) {
      return ipcRenderer.invoke('request:http', config)
    },
    get(...args: unknown[]) {
      return ipcRenderer.invoke('request:http:get', args)
    },
    post(...args: unknown[]) {
      return ipcRenderer.invoke('request:http:post', args)
    }
  },
  updateNow() {
    ipcRenderer.send('update:now')
  },
  openDevTools() {
    ipcRenderer.send('openDevTools')
  },
  onUpdater(callback: (...args: unknown[]) => void) {
    ipcRenderer.on('onUpdater', function (e, data) {
      callback(data)
    })
  }
})
